package com.xinzhi.controller;

import com.xinzhi.service.impl.LoanApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 处理贷款相关请求的控制器。
 */
@RestController
@RequestMapping("/loan")
public class LoanController {

    @Autowired
    private LoanApprovalService loanApprovalService;

    /**
     * 审批贷款申请。
     *
     * @param applicationId 贷款申请的ID
     * @param approvalDate 审批日期
     * @param approverId 审批人的ID
     * @return 表示操作结果的消息
     */
    @PostMapping("/approve")
    public String approveLoanApplication(
            @RequestParam Integer applicationId,
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date approvalDate,
            @RequestParam Integer approverId) {

        try {
            loanApprovalService.approveLoanApplication(applicationId, approvalDate, approverId);
            return "申请成功!";
        } catch (Exception e) {
            e.printStackTrace();
            return "报错啦笨蛋小心一点: " + e.getMessage();
        }
    }
}
